<template>
  <div class="home">
    <div class="lottery-container">
      <img src="../../assets/images/background.png" />
      <div class="lottery-img"><img src="../../assets/images/title.png" /></div>
      <div class="lottery-title">幸运抽奖</div>
      <div class="lottery-consumables">
        <label>当前矿石数：</label><span>{{ consumables_count }}</span>
      </div>
      <div class="lottery-main"><Lottery /></div>
      <div class="lottery-list">
        <h2>中奖列表</h2>
        <ul>
          <li v-for="(item, index) in resultList" :key="index">
            {{ index + 1 }}-{{ item }}
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script lang="ts" >
import { defineComponent } from "vue";
import Lottery from "@comps/lottery/index.vue";
import ajax from "../../config/fetch";
import { Result } from "../../../types/fetch";
import { mapActions } from "vuex";
const getComsumeUrl: string = "/api/get_consumables_info";

export default defineComponent({
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      saveCountConsume: "saveCountConsume",
    }),
    getComsume() {
      ajax(getComsumeUrl).then((res: Result) => {
        this.saveCountConsume({
          consume: res.data.consume_count,
          consumables: res.data.consumables_count,
        });
      });
    },
  },
  mounted() {
    this.getComsume();
  },
  computed: {
    consumables_count() {
      return this.$store.state.setting.consumables;
    },
    resultList() {
      return Array.from(this.$store.state.setting.lotteryResults);
    },
  },
  components: {
    Lottery,
  },
});
</script>

<style lang="less">
.home {
  position: relative;
  top: 20%;
  display: flex;
  justify-content: center;
}
.lottery-container {
  background: #568fff;
  position: relative;
  height: 100%;
  width: 775px;
}
.lottery-container > img {
  position: absolute;
  background: #2c68ff;
  top: 0;
  left: 0;
  width: 100%;
}
.lottery-img {
  position: relative;
  padding-top: 82px;
  z-index: 1;
  width: 500px;
  margin: 0 auto;
}
.lottery-title {
  position: relative;
  padding-left: 20px;
  font-size: 20px;
  line-height: 28px;
  color: #fadd95;
  margin: 40px 0px 10px 20px;
}
.lottery-title:before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  margin: auto 0;
  width: 8px;
  height: 20px;
  display: block;
  border-radius: 50px;
  background: #e37815;
}
.lottery-img img {
  width: 100%;
  height: 65px;
}
.lottery-main {
  z-index: 2;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.lottery-consumables {
  position: relative;
  margin-bottom: 20px;
  padding-left: 40px;
  color: #fff;
}
.lottery-list {
  position: relative;
  padding-left: 20px;
  color: #fff;
  li{
    padding-left: 20px;
    margin: 4px 0;
  }
}
</style>
